﻿using System;
using System.Windows.Input;
using Acme.Common.Infrastructure;
using Acme.MVVM.Scenarios.Infrastructure;
using Microsoft.Practices.Prism.Interactivity.InteractionRequest;

namespace Acme.MVVM.Scenarios.Views
{
    public class DialogInteractionRequestViewModel : ScenarioViewModelBase
    {

        readonly InteractionRequest<Notification> _notificationFromViewModelInteractionRequest;
        readonly InteractionRequest<Confirmation> _confirmationFromViewModelInteractionRequest;

        public ICommand NotificationDialogCommand
        {
            get { return new RelayCommand(() => RaiseNotificationFromViewModelInteractionRequest("Hello from view model Prism Interaction Request")); }
        }

        public ICommand ConfirmationDialogCommand
        {
            get { return new RelayCommand(RaiseConfirmationFromViewModelInteractionRequest); }
        }

        public override string TabHeaderText
        {
            get { return "Dialog Interaction Request"; }
        }

        /// <summary>
        /// Gets the notification from view model interaction request. View binds to this property
        /// </summary>
        public IInteractionRequest NotificationFromViewModelInteractionRequest
        {
            get { return _notificationFromViewModelInteractionRequest; }
        }

        /// <summary>
        /// Gets the notification from view model interaction request. View binds to this property
        /// </summary>
        public IInteractionRequest ConfirmationFromViewModelInteractionRequest
        {
            get { return _confirmationFromViewModelInteractionRequest; }
        }

        public DialogInteractionRequestViewModel()
        {

            _notificationFromViewModelInteractionRequest = new InteractionRequest<Notification>();
            _confirmationFromViewModelInteractionRequest = new InteractionRequest<Confirmation>();
        }

        void RaiseNotificationFromViewModelInteractionRequest(String message)
        {
            _notificationFromViewModelInteractionRequest.Raise(
                new Notification { Content = message, Title = "MVVM Scenario" },
                dummy => { });
        }

        void RaiseConfirmationFromViewModelInteractionRequest()
        {
            _confirmationFromViewModelInteractionRequest.Raise(
                new Confirmation { Content = "Are you sure you want to close this confirmation dialog?", Title = "MVVM Scenario" },
                confirmation =>
                {
                    if (confirmation.Confirmed)
                    {
                        RaiseNotificationFromViewModelInteractionRequest("You just clicked OK");
                    }
                });
        }
    }
}
